package com.shbaiche.bifenba.adapter.video;

import android.app.Activity;
import android.content.Context;
import android.media.Image;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.video.ArticleVo;
import com.shbaiche.bifenba.ui.video.VideoDetailActivity;
import com.shbaiche.bifenba.ui.video.VideoTeamFragment;
import com.shbaiche.bifenba.view.CircularImage;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * FileName: VideoAdapter
 * Author: 刘
 * Date: 2018/8/2 06:57
 * Description: ${DESCRIPTION}
 */
public class VideoAdapter extends CommonAdapter<String> {
    private Context mContext;
    private List<ArticleVo> list;

    public VideoAdapter(Context context, List<String> datas, List<ArticleVo> list, int layoutId) {
        super(context, layoutId, datas);
        this.list = list;
        this.mContext = context;
    }

    @Override
    protected void convert(ViewHolder viewHolder, String url, int position) {
        JCVideoPlayerStandard player = viewHolder.getView(R.id.player_list_video);
        LinearLayout layout = viewHolder.getView(R.id.adapter_video_layout);
        TextView name = viewHolder.getView(R.id.tv_video_name);
        TextView time = viewHolder.getView(R.id.tv_video_time);
        TextView commet = viewHolder.getView(R.id.tv_video_comment);
        CircularImage head = viewHolder.getView(R.id.img_video_icon);

        if (list != null) {
            final ArticleVo vo = list.get(position);
            if (vo.getAuthor() != null) {
                name.setText(vo.getAuthor().getName());
                Glide.with(mContext).load(vo.getAuthor().getPhoto()).placeholder(R.drawable.ic_my_head).error(R.drawable.ic_my_head).into(head);
            }
            time.setText(vo.getPublishTime() + "");
            commet.setText(vo.getBrowseNum() + "");


            if (player != null) {
                player.release();
            }
            player.setUp(url, JCVideoPlayer.SCREEN_LAYOUT_LIST, vo.getTitle() + "");
            Glide.with(mContext).load(vo.getThumbnail() + "").into(player.thumbImageView);
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Bundle b = new Bundle();
                    b.putLong("id", vo.getId());
                    VideoDetailActivity.launch((Activity) mContext,b);
                }
            });
        }
    }
}